#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <string>
#include <cctype>
#include <cstdlib>
#include <map>
#include <bitset>
#include <unordered_map>
#include <ctime>
#include <vector>
#include <queue>
#include <list>
#include <stack>

#define R register
#define L long
#define LL long long
#define I inline
#define U unsigned
using namespace std;
I LL read()
{
    R LL   x;
    R bool f;
    R char c;
    for(f=0;(c=getchar())<'0'||c>'9';f=c=='-');
    for(x=c-'0';(c=getchar())>='0'&&c<='9';x=(x<<3)+(x<<1)+c-'0');
    return f?-x:x;
}
#define MAXN 111
int a[MAXN],b[MAXN];

int main()
{
     freopen("7-2.in","r",stdin);
    //freopen("7-2.out","w",stdout);
    int n=read();
    for(int i=0;i<n;a[i]=read(),++i);
    for(int i=0;i<n;b[i]=read(),++i);
    bool flag = true;
    int ns=1;
    for(;ns<n;++ns)
        if(b[ns-1]>b[ns])
            break;
    for(int i=ns;i<n;++i)
        if(a[i]!=b[i])
        {
            flag=false;
            break;
        }
    if(flag)
    {
        printf("Insertion Sort\n");
        if(ns!=n)
            sort(b,b+ns+1);
    }
    else
    {
        //找到最小的没有merge的区间，要不然可能会出现第一个排完恰好有序的情况，最后一个点会炸
        for(int i=ns+1,j=0;i<n;++i,++j)
            if(b[i-1]>b[i])
                ns=min(ns,j+1),j=0;
        int bu=1;
        while(bu<=ns)bu<<=1;
        printf("Merge Sort\n");
        for(int i=0;i<n;sort(b+i,b+min(i+bu,n)),i+=bu);
    }
    for(int i=0;i<n;printf("%s%d",i?" ":"",b[i]),++i);
    
    
    fclose(stdin);
    fclose(stdout);
    return 0;
}